/*
 * Copyright (C) 2012 Le Tuan Anh <anh.takaji@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ezcms.client;

import ezcms.dto.Conference;
import ezcms.dto.Location;
import ezcms.ejb.ConferenceServiceRemote;
import ezcms.exceptions.BusinessLogicException;
import ezcms.exceptions.LookupException;
import ezcms.exceptions.PresentationException;
import ezcms.exceptions.ServiceInvokeException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Le Tuan Anh <anh.takaji@gmail.com>
 */
public class ConferenceServiceDelegate {

    private static final Logger logger = Logger.getLogger(ConferenceServiceDelegate.class.getName());
    private ConferenceServiceRemote remote = null;

    public ConferenceServiceDelegate() throws LookupException {
        remote = lookupConferenceServiceRemote();
    }

    private ConferenceServiceRemote lookupConferenceServiceRemote() throws LookupException {
        EJBLocator locator = EJBLocator.getInstance();
        try {
            return locator.getConferenceServiceFacade();
        } catch (PresentationException ex) {
            //TODO: log
            logger.log(Level.SEVERE, null, ex);
            throw new LookupException(ex);
        }
    }

    /* Start service methods proxy */
    //
    public void saveLocation(Location location) throws ServiceInvokeException {
        try {
            remote.saveLocation(location);
        } catch (BusinessLogicException ex) {
            //TODO: log
            logger.log(Level.SEVERE, "Error while invoking service method saveLocation", ex);
            throw new ServiceInvokeException(ex);
        }
    }

    public void deleteLocation(Location location) throws ServiceInvokeException {
        try {
            remote.deleteLocation(location);
        } catch (BusinessLogicException ex) {
            //TODO: log
            logger.log(Level.SEVERE, "Error while invoking service method deleteLocation", ex);
            throw new ServiceInvokeException(ex);
        }
    }

    public Location getLocationByName(String name) throws ServiceInvokeException {
        try {
            return remote.getLocationByName(name);
        } catch (BusinessLogicException ex) {
            //TODO: log
            logger.log(Level.SEVERE, "Error while invoking service method getLocationByName", ex);
            throw new ServiceInvokeException(ex);
        }
    }

    public void saveConference(Conference conference) throws ServiceInvokeException {
        try {
            remote.saveConference(conference);
        } catch (BusinessLogicException ex) {
            //TODO: log
            logger.log(Level.SEVERE, "Error while invoking service method saveConference", ex);
            throw new ServiceInvokeException(ex);
        }
    }

    public void deleteConference(Conference conference) throws ServiceInvokeException {
        try {
            remote.deleteConference(conference);
        } catch (BusinessLogicException ex) {
            //TODO: log
            logger.log(Level.SEVERE, "Error while invoking service method deleteConference", ex);
            throw new ServiceInvokeException(ex);
        }
    }

    public List<Conference> getActiveConferences() throws ServiceInvokeException {
        try {
            return remote.getActiveConference();
        } catch (BusinessLogicException ex) {
            //TODO: log
            logger.log(Level.SEVERE, "Error while invoking service method deleteConference", ex);
            throw new ServiceInvokeException(ex);
        }
    }

    public List<Conference> getAllConferences() throws ServiceInvokeException {
        try {
            return remote.getAllConferences();
        } catch (BusinessLogicException ex) {
            //TODO: log
            logger.log(Level.SEVERE, "Error while invoking service method deleteConference", ex);
            throw new ServiceInvokeException(ex);
        }
    }

    public Conference getConferenceById(long id) throws ServiceInvokeException {
        try {
            return remote.getConferenceById(id);
        } catch (BusinessLogicException ex) {
            //TODO: log
            logger.log(Level.SEVERE, "Error while invoking service method getConferenceById", ex);
            throw new ServiceInvokeException(ex);
        }
    }

    public Location getLocationById(long id) throws ServiceInvokeException {
        try {
            return remote.getLocationById(id);
        } catch (BusinessLogicException ex) {
            //TODO: log
            logger.log(Level.SEVERE, "Error while invoking service method getLocationById", ex);
            throw new ServiceInvokeException(ex);
        }
    }
}
